package com.lpc.kotlintest

import org.junit.Assert
import org.junit.Test

/**
 * 功能:类与继承
 *
 * 描述:
 *
 * Created by lipc0113 on 2018/7/12.
 */
class ExampleUnitTest2 {

    @Test
    fun addition_isCorrect() {


//        var p = P(101, "haha")
//        println("p ${p.name}")

//        var pp = PP(101, "haha2")
//        println("pp ${pp.name}")

//        var person = Person(200, "lipc")
//        println("person ${person.name}")

//        var person = Person(200, "lipc", true)
//        println("person ${person.isMan}")

//        var person = Person(200)
//        println("person ${person.name}")

        var student = Student(1, 1)
        println("student ${student.name}")

        Assert.assertEquals(4, 2 + 2)
    }

    @Test
    fun addition_isCorrect2() {

        var v = Animal.newInstance("tiger")
        println("v ${v.name} ${Animal.Companion.id}")
    }

    data class P public constructor(var id: Int, val name: String)

    class PP(id: Int, var name: String)

    class Student(
            var index: Int,
            override var id: Int
    ) : Person(id),
            OnClick,
            OnTouch {
        override fun a() {
            
        }

        override var i1: Int
            get() = 1
            set(value) {}

        override fun onClick() {

            println("onClick")
        }

        override fun onTouch() {

            println("onTouch")
        }

        override fun test() {

        }

    }

    open class Person(open var id: Int, var name: String = "lpc") {

        init {
            id = 100
            println("person inits")
        }

        public var isMan: Boolean = false

        constructor(
                id: Int,
                name: String,
                isMan: Boolean
        ) : this(id, name) {

            this.isMan = isMan
            println("person inits2")
        }

        constructor(
                id: Int
        ) : this(id, "hehe") {

            name = "123"
            println("person inits3")
        }

        open fun test() {

        }
    }

    class Animal(var name: String) {

        companion object {

            val id: Int = 123

            fun newInstance(name: String): Animal {

                return Animal(name)
            }

        }

    }

    interface OnClick {

        var i1: Int

        var i2: Int
            get() = 1
            set(value) {
                i2 = value
            }

        fun onClick()

        fun a()
    }

    interface OnTouch {

        fun onTouch()

        fun a()
    }
}